package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.LeaseAgreementMapper;
import com.atguigu.lease.web.admin.service.*;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {
    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;
    @Autowired
    private ApartmentInfoService apartmentInfoService;
    @Autowired
    private RoomInfoService roomInfoService;
    @Autowired
    private PaymentTypeService paymentTypeService;
    @Autowired
    private LeaseTermService leaseTermService;
    @Override
    public IPage<AgreementVo> customPage(IPage<AgreementVo> agreementVoIPage, AgreementQueryVo queryVo) {
        return leaseAgreementMapper.itemPage(agreementVoIPage,queryVo);
    }

    /**
     * @Description: 
     * @Param: [leaseAgreement]
     * @return: void
     * @Author: ahang
     * @Date: 2025/7/29
     */
/**
 * @Description: 简单的单表修改
 * @Param: [leaseAgreement]
 * @return: void
 * @Author: ahang
 * @Date: 2025/7/29
 */

@Override
    public void customSaveOrUpdate(LeaseAgreement leaseAgreement) {
    super.saveOrUpdate(leaseAgreement);
    }

    @Override
    public AgreementVo customGetById(Long id) {
        LeaseAgreement agreement = super.getById(id);
        Long apartmentId = agreement.getApartmentId();
        Long roomId = agreement.getRoomId();
        Long paymentTypeId = agreement.getPaymentTypeId();
        Long leaseTermId = agreement.getLeaseTermId();
//        查询公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoService.getById(apartmentId);
//        查询房间信息
        RoomInfo roomInfo = roomInfoService.getById(roomId);
//        查询支付方式信息
        PaymentType paymentType = paymentTypeService.getById(paymentTypeId);
//        查询租期信息
        LeaseTerm leaseTerm = leaseTermService.getById(leaseTermId);
        AgreementVo agreementVo = new AgreementVo();
        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setLeaseTerm(leaseTerm);
        BeanUtils.copyProperties(agreement, agreementVo);
        return agreementVo ;

    }

}




